package com.demo.springBootDemo02.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class IndexController {

	@Value("${website}")
	private String website;

	@Autowired
	private Site site;

	@Autowired
	private Environment env;

	@RequestMapping("/")
	public Object index() {
		return "welcome to " + website + "-" + site.getCopyright();
	}

	@RequestMapping("/hello/{name}")
	public Object hello(@PathVariable("name") String name) {
		return String.format("Hello,%s", name);
	}

	@RequestMapping("/runtime")
	public Object runtime() {
		String version = env.getProperty("runtime.system.version");
		String workmode = env.getProperty("runtime.config.workmode");
		String systemAlias = env.getProperty("runtime.systemAlias");
		return String.format("systemAlias=%s,\nversion=%s,\nworkmode=%s", systemAlias, version, workmode);
	}

}
